package org.jtb.quickr;

import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

class PhotosGetInfoRequest extends MethodRequest {
    private String staticUrl;
    private String photoId;
    private String photoSecret;
    
    protected PhotosGetInfoRequest(String baseUrl, String apiKey, String photoId, String photoSecret, String staticUrl) throws QuickrException {
        super(baseUrl, apiKey, "flickr.photos.getInfo");
        this.photoId = photoId;
        this.photoSecret = photoSecret;
        this.staticUrl = staticUrl;
    }
    
    
    protected Map<String,String> getArgs() {
        putArg("photo_id", photoId);
        if (photoSecret != null) {
            putArg("secret", photoSecret);
        }
        
        return super.getArgs();
    }
    
    public PhotoResponse execute() throws QuickrException {
        FlickrUrl furl = new ServiceMethodUrl(getBaseUrl(), getArgs(), getApiKey(), getMethod());
        
        Get get = new Get(furl.getUrl());
        InputStream is = get.execute();
        
        PhotoResponse pres = new PhotoResponse(is, staticUrl);
        
        return pres;
    }
}
